package com.czumi.javawx.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.czumi.javawx.constants.AppConst;
import com.czumi.javawx.dao.entity.SysUser;



/**  
* 创建时间：2017年9月29日 下午6:28:32  
* 项目名称：tzyz  
* @author make.yuan  
* @version 1.0   
* @since    JDK 1.8
* 文件名称：LoginInterceptor.java  
* 类说明：  
*/
public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		// TODO Auto-generated method stub
		SysUser user = (SysUser)request.getSession().getAttribute(AppConst.SESSION_ADMIN_KEY);
		if(user!=null) {
			return true;
		}else {
			response.sendRedirect(request.getContextPath()+"/login");
			return false;
		}
		
	}

}
  
